package com.jrx.anytxn.transaction.mapper.ext;

import com.jrx.anytxn.transaction.entity.TlThirdPartyPayment;
import com.jrx.anytxn.transaction.mapper.base.TlThirdPartyPaymentMapper;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;

public interface ExtTlThirdPartyPaymentMapper extends TlThirdPartyPaymentMapper {

    /**
     * 根据请求流水号查询三方还款流水表
     *
     * @param payId      请求流水号
     * @param customerId 客户id
     * @param tenantId   租户id
     * @return 三方还款流水表
     */
    TlThirdPartyPayment selectByPayId(@Param(value = "payId") String payId,
                                      @Param(value = "customerId") String customerId,
                                      @Param(value = "tenantId") String tenantId);

    /**
     * 批量根据状态查询
     *
     * @param sumStatus
     * @return
     */
    List<TlThirdPartyPayment> selectBySumStatus(@Param(value = "sumStatus") String sumStatus, @Param(value = "grayVersion") String grayVersion);

    /**
     * 根据主键、客户id及租户id修改三方还款流水
     *
     * @param tlThirdPartyPayment 三方还款流水
     */
    int updateByIdAndCustomerIdAndTenantId(TlThirdPartyPayment tlThirdPartyPayment);


    /**
     * 根据还款流水号查询三方还款信息
     *
     * @param seqNo      还款流水
     * @param customerId 客户id
     * @param tenantId   租户id
     * @return 还款流水信息
     */
    TlThirdPartyPayment selectPaymentStatusBySeqNo(@Param(value = "seqNo") String seqNo,
                                                   @Param(value = "customerId") String customerId,
                                                   @Param(value = "tenantId") String tenantId);

    /**
     * 根据客户id查询三方还款信息
     *
     * @param sumStatus  还款状态
     * @param customerId 客户id
     * @param tenantId   租户id
     * @return 还款流水信息
     */
    int selectPaymentStatusByCustomerIdAndSumStatus(@Param(value = "sumStatus") String sumStatus,
                                                    @Param(value = "customerId") String customerId,
                                                    @Param(value = "tenantId") String tenantId);

    void batchInsert(List<TlThirdPartyPayment> list);

    List<TlThirdPartyPayment> selectPaymentBysumStatusAndChannel(@Param(value = "sumStatus") String sumStatus,
                                                                 @Param(value = "channel") String channel,
                                                                 @Param(value = "businessDate") Date businessDate);

    /**
     * 根据还款类型，业务时间，渠道，状态获取第三方还款流水
     *
     * @param businessDate
     * @param paymentType
     * @param sumStatus
     * @param channel
     * @return List<TlThirdPartyPayment>
     * @author liuyang
     * @date 2021-03-11
     */
    List<TlThirdPartyPayment> selectByTypeAndStatus(@Param("businessDate") Date businessDate, @Param("paymentType") String paymentType, @Param("sumStatus") String sumStatus, @Param("channel") String channel);

    /**
     * 根据还款类型，业务时间，渠道，状态获取第三方还款流水id
     *
     * @param businessDate
     * @param paymentType
     * @param sumStatus
     * @param channel
     * @return List<Long>
     * @author liuyang
     * @date 2021-03-22
     */
    List<Long> selectIdByTypeAndStatus(@Param("businessDate") Date businessDate, @Param("paymentType") String paymentType, @Param("sumStatus") String sumStatus, @Param("channel") String channel);


    /**
     * 根据还款类型，业务时间，渠道，状态获取第三方还款流水
     *
     * @param businessDate
     * @param paymentTypeList
     * @param sumStatus
     * @param channel
     * @return List<TlThirdPartyPayment>
     * @author liuyang
     * @date 2021-03-11
     */
    List<TlThirdPartyPayment> selectFilePayForBatch(Date businessDate, List<String> paymentTypeList, String sumStatus, String channel);

    /**
     * 批量更新
     *
     * @param thirdPartyPaymentList
     */
    void batchUpdateLogForBatch(List<TlThirdPartyPayment> thirdPartyPaymentList);

    /**
     * 批量查询
     */
    List<TlThirdPartyPayment> selectByBusinessDate(@Param("businessDate") Date businessDate, @Param("sumStatus") String sumStatus);

    /**
     * 查询订单最近一次还款
     *
     * @param loanId
     * @param customerId
     * @param tenantId
     * @return
     */
    TlThirdPartyPayment findLastByCustomerIdAndLoanId(@Param(value = "loanId") String loanId,
                                                      @Param(value = "customerId") String customerId,
                                                      @Param(value = "tenantId") String tenantId);


    List<TlThirdPartyPayment> selectPaymentBySumStatusListAndChannel(@Param(value = "sumStatusList") List<String> sumStatusList,
                                                                     @Param(value = "channel") String channel,
                                                                     @Param(value = "businessDate") Date businessDate);
    /**
     * 查询第三方还款
     *
     * @param channel 渠道
     * @param customerId 客户ID
     * @param tenantId 租户ID
     * @param seqNo 流水号
     * @param beginDate 发起开始时间
     * @param endDate 发起结束时间
     * @return TlThirdPartyPayment
     */
    List<TlThirdPartyPayment> selectByCondSelectivePage(@Param("tenantId") String tenantId, @Param("channel") String channel,
                                                        @Param("customerId") String customerId, @Param("seqNo") String seqNo,
                                                        @Param("beginDate") Date beginDate, @Param("endDate") Date endDate);

    /**
     * 查询第三方还款流水表信息
     *
     * @param tenantId 租户ID
     * @param seqNo 流水号
     * @param customerId 客户ID
     * @return TlThirdPartyPayment
     */
    TlThirdPartyPayment selectThirdPartyPaymentBySeqNoAndCusId(@Param("tenantId") String tenantId, @Param("customerId") String customerId, @Param("seqNo") String seqNo);
}
